package com.center.growcenterserver.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.center.growcenterserver.common.R;
import com.center.growcenterserver.model.domain.Student;
import com.center.growcenterserver.model.domain.StudentCourse;
import com.center.growcenterserver.service.StudentCoursesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("studentcourses")
public class StudentCoursesController {

    @Autowired
    private StudentCoursesService studentCoursesService;

    /**
     * 管理界面调用：返回所有学生以及课程、成绩
     */
    @GetMapping("")
    public R allStudentCourses(@RequestParam(defaultValue = "1") int curPage, @RequestParam(defaultValue = "100") int pageSize) {
        IPage<StudentCourse> page = new Page<>(curPage, pageSize);
        return studentCoursesService.allStudentCourses(page);
    }

    @GetMapping("/{studentId}/courses")
    public R studentCoursesById(
            @PathVariable String studentId,
            @RequestParam(defaultValue = "1") int curPage,
            @RequestParam(defaultValue = "10") int pageSize) {
        IPage<StudentCourse> page = new Page<>(curPage, pageSize);
        return studentCoursesService.getStudentCoursesById(studentId, page);
    }

    @GetMapping("/{studentId}/coursesname")
    public R CoursesNameById(
            @PathVariable String studentId,
            @RequestParam(defaultValue = "1") int curPage,
            @RequestParam(defaultValue = "10") int pageSize) {
        IPage<Map<String, Object>> page = new Page<>(curPage, pageSize);
        return studentCoursesService.getCoursesNameById(studentId, page);
    }
}


